﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>填充从表</title>
    <link href="../../../../DataUser/Style/ccbpm.css" rel="stylesheet" type="text/css" />
    <script src="../../../Scripts/easyUI145/jquery.min.js" type="text/javascript"></script>
    <script src="../../../Scripts/easyUI145/jquery.easyui.min.js" type="text/javascript"></script>

    <script src="../../../Scripts/QueryString.js" type="text/javascript"></script>
    <script src="../../../Scripts/config.js" type="text/javascript"></script>
    <script src="../../../Scripts/QueryString.js" type="text/javascript"></script>
    <script src="../../../Comm/Gener.js" type="text/javascript"></script>
    <script src="DDLBar.js" type="text/javascript"></script>
    <script src="../../CCFlowEnum.js" type="text/javascript"></script>
    <script src="../../Admin.js"></script>
    <script type="text/javascript">
        var extType = "";
        $(function () {

            extType = GetQueryString("ExtType");
            extType = extType == null || extType == undefined ? "" : extType;

            InitBar("Dtls");

            //查询出来数据.
            //更新节点表单类型.
            var frmID = GetQueryString("FK_MapData");
            var refPK = GetQueryString("RefPK");



            var thisPK = refPK + "_FullData";
            if (extType == "PageLoadFull")
                thisPK = refPK;

            var en = new Entity("BP.Sys.MapExt");
            en.MyPK = thisPK;
            en.SetPKVal(en.MyPK);
            var n = en.RetrieveFromDBSources();

            var tag1 = en.Tag1;


            //获得从表.
            var mapDtls = new Entities("BP.Sys.MapDtls");
            mapDtls.Retrieve("FK_MapData", frmID);

            if (mapDtls.length == 0) {
                $("#doc").html("<h3>该表单没有从表.</h3>");
                return;
            }
            var tag5 = en.Tag5 || "0";
            $("#RB_Type_" + tag5).attr("checked", true);
            if (tag5 == "0") {
                $("#doc").show();
                $("#TB_Tag1").hide();
            } else {
                $("#doc").hide();
                $("#TB_Tag1").show();
                $("#TB_Tag1").val(en.Tag1);
                $("#TB_Post").val(en.Tag4);
            }
            var html = "<table style='width:99%;'>";
            for (var i = 0; i < mapDtls.length; i++) {
                var dtl = mapDtls[i];
                var sql = "";
                if (tag1 != "" && tag1 != null) {
                    //第二批创建从表No是否在第一批创建从表的填充SQL里
                    if (tag1.indexOf(dtl.No) != -1)
                        sql = tag1.split("$")[i + 1].replace(dtl.No + ":", ""); //分割字符串，获取sql语句
                    else
                        sql = "";
                }

                html += "<tr>";
                html += "<td>" + dtl.No + " - " + dtl.Name + "</td>";
                html += "</tr>";

                html += "<tr>";
                html += "<td>";
                html += "<textarea id='" + dtl.No + "' style='width:98%;' >" + FormatSQL(sql) + "</textarea>";
                html += "</td>";
                html += "</tr>";
            }
            $("#doc").html(html);
        });

        function Save() {

            //更新节点表单类型.
            var frmID = GetQueryString("FK_MapData");
            var refPK = GetQueryString("RefPK");

            var thisPK = refPK + "_FullData";
            if (extType == "PageLoadFull")
                thisPK = refPK;

            var en = new Entity("BP.Sys.MapExt");
            en.MyPK = thisPK;
            en.SetPKVal(en.MyPK);
            var n = en.RetrieveFromDBSources();
            en.FK_MapData = frmID;
            if (extType == "PageLoadFull") {
                en.AttrOfOper = "";
                en.ExtType = "PageLoadFull";
            }
            else {
                en.AttrOfOper = GetQueryString("KeyOfEn");
                en.ExtType = "FullData";
                en.DoWay = "1";
                //en.DBType = "1";
            }

            //生成SQL, 执行保存.
            //格式为: #ND101$ SELECT * FROM SXX WHERE AA='11';

            //获得从表.
            var mapDtls = new Entities("BP.Sys.MapDtls");
            mapDtls.Retrieve("FK_MapData", frmID);

            var tag4 = $("#TB_Post").val();
            tag4 = tag4.replace(/"/g, "'").replace(/'/g, "~");
            en.Tag4 = tag4;

            en.Tag5 = $("input[name='RB_Type']:checked").val();

            if (en.Tag5 == 0) {
                var tag1 = "";
                for (var i = 0; i < mapDtls.length; i++) {

                    var dtl = mapDtls[i];

                    var sql = $("#" + dtl.No).val();
                    tag1 += "$" + dtl.No + ":" + sql;
                }
                en.Tag1 = tag1;
            } else {
                en.Tag1 = $("#TB_Tag1").val();
            }

            en.SetPara("FullDataDtls", "Dtls"); //获得选择的值.

            if (n == 0)
                en.Insert();
            else
                en.Update();

            Reload();
        }
        function ChangeShow(type) {
            if (type == 0) {
                $("#doc").show();
                $("#TB_Tag1").hide();
            } else {
                $("#doc").hide();
                $("#TB_Tag1").show();
            }

        }
    </script>
</head>
<body>
    <form id="cc">

        <div id="bar"> </div>
        <div>
            从表填充方式：
            <input type="radio" name="RB_Type" id="RB_Type_0" value="0" onchange="ChangeShow(0)" />分别填充
            <input type="radio" name="RB_Type" id="RB_Type_1" value="1" onchange="ChangeShow(1)" />请求URL一次性获取数据填充
        </div>
        <div id="doc"></div>
        <textarea rows="4" name="TB_Tag1" id="TB_Tag1" style="width: 98%;"> </textarea>
        <p>POST请求参数:</p>
        <textarea rows="4" name="TB_Post" id="TB_Post" style="width: 98%;"> </textarea>

    </form>


    <fieldset>
        <legend>帮助.</legend>
        <ul>
            <li>填充从表的SQL </li>
            <li>返回一个数据源，该数据源的列，需要与从表的列匹配，对于匹配上的数据自动填充.</li>
            <li>实例:<font color="green">SELECT * FROM Demo_Resume WHERE RefPK='@Key' </font></li>
            <li>@Key 是系统约定的标记，就是选择的编号或者ID. </li>
            <li>这个数据源就会清空的方式复制到从表里面去. </li>
        </ul>
    </fieldset>

</body>
</html>
